/**
 * @author tmh
 * @date 2024/9/13 20:44
 * @description
 */
public class T53最大子数组和 {
    public int maxSubArray(int[] nums) {
        int sum =  0;
        int maxSum = nums[0];
        for (int num: nums){
            //比较这个数和 这个数加上前面的sum的大小，然后更新sum，更新maxSum
            sum = Math.max(num,sum+num);
            maxSum=Math.max(maxSum,sum);
        }
        return maxSum;
    }

}
